import React,{Component} from "react"
export default class Footer extends Component {
    constructor(){
        super();
        this.state = {num:1, title:'123'};
        //事件的绑定，使this指向
        this.add = this.add.bind(this);
    }
    //以后尽量用箭头函数声明事件处理函数，省去bind绑定
    add1 = ()=>{
        console.log(this);
        this.setState({num:this.state.num+2});
    }
    add(){
        //add方法不是组件实例调用，是直接调用
        //类中自定义的方法默认开启了严格模式,阻止this指向window
        console.log(this);
        this.setState({num:this.state.num+1})
    }
    re = () => {
        this.setState({num:this.state.num-this.state.num+1});
    }
    componentDidMount(){
        console.log(this);
    }
    render(){
        return(
            <div>
                <h2>{this.state.num}</h2>
                <button onClick = {this.add}>点我+1</button>
                <button onClick = {this.add1}>点我+2</button>
                <button onClick = {this.re}>恢复为1</button>
            </div>
        )
    }
}